﻿using System.IO;
using System.Text;
using log4net;
using log4net.Core;
using log4net.Filter;
using log4net.Layout;

namespace Battle.Net.Infrastructure
{
    internal class Logging
    {
        private Logging()
        {

            var logPath = Path.GetDirectoryName(typeof(Logging).Assembly.GetName().CodeBase);

            var fileAppender = new log4net.Appender.FileAppender
                {
                    AppendToFile = true,
                    Encoding = Encoding.UTF8,
                    File = logPath + "\\Blizzard.log",
                    Layout = new PatternLayout("%date [%thread] %-5level - %message %newline %exception")
                };
            fileAppender.AddFilter(new LevelRangeFilter(){AcceptOnMatch = true, LevelMin = Level.Warn, LevelMax = Level.Fatal});
            log4net.Config.BasicConfigurator.Configure(fileAppender);
            
        }

        private ILog GetLog()
        {
            return LogManager.GetLogger(typeof (Logging));
        }

        private static Logging Instance { get; set; }

        internal static ILog Log 
        {
            get
            {
                if (Instance == null)
                    Instance = new Logging();

                return Instance.GetLog();
            }
        }
    }
}
